package com.tanhua.server.service;

import com.itheima.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.HuanXinUserVo;
import com.tanhua.server.interceptor.UserThreadLocal;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @Author Pan Rundong
 * @Date 2023-03-04 15:36
 * @Desc 环信Service
 */
@Service
public class HuanXinService {
    @DubboReference(version = "1.0.0")
    private UserApi userApi;

    /**
     * 查询环信用户
     *
     * @param
     * @return com.tanhua.model.vo.HuanXinUserVo
     * @Author Pan Rundong
     */
    public HuanXinUserVo getHuanXinUser() {
        //1.获取用户Id查询环信账户
        Long userId = UserThreadLocal.getUserId();
        User user = userApi.findById(userId);

        //2.判断user是否存在
        if (user == null) {
            //不存在返回null
            return null;
        }
        //存在封装Vo并返回
        return new HuanXinUserVo(user.getHxUser(), user.getHxPassword());
    }
}
